package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oa.bean.CarApply;
import com.oa.bean.CarManage;
import com.oa.dao.CarDao;
import com.oa.service.CarManageService;

@Service
public class CarManageServiceImol implements CarManageService {

	@Autowired
	CarDao carDao;
	
	@Override
	public String addCar(CarManage carManage) {
		// TODO Auto-generated method stub
		Integer result = carDao.insertCarByCar(carManage);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public String MoveCar(Integer cm_id) {
		// TODO Auto-generated method stub
		Integer result = carDao.deleteCarById(cm_id);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public Map<String, Object> getCarManageList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		Page page = PageHelper.startPage((int)map.get("currentPage"), 2, "cm_id desc");
		List<CarManage>list = carDao.selectCarAllList(map);
		Map<String,Object>result = new HashMap<>();
		result.put("carList", list);
		result.put("mixNums", page.getPages());
		result.put("limit", 2);
		return result;
	}

	@Override
	public String addCarApply(CarApply carApply) {
		// TODO Auto-generated method stub
		Integer result = carDao.insertCarApply(carApply);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public List<CarManage> getCnameList() {
		// TODO Auto-generated method stub
		List<CarManage> list = carDao.selectCnameCid();
		return list;
	}

	@Override
	public List<CarApply> getMyCarApply(int uid) {
		// TODO Auto-generated method stub
		List<CarApply> list = carDao.selectCarApplyList(uid);
		return list;
	}

	@Override
	public Map<String, Object> getCarApplyAll(CarApply carApply,Integer currentPage) {
		// TODO Auto-generated method stub
		Page page = PageHelper.startPage(currentPage, 2, "ca_id desc");
		List<CarApply> list = carDao.selectCarApplyAll(carApply);
		Map<String,Object> result = new HashMap<>();
		result.put("carApplyList", list);
		result.put("mixNums", page.getPages());
		result.put("limit", 2);
		return result;
	}
/**
 * 0 表示车辆被禁用
 * 1表示可以 
 * 2表示被占用
 */
	@Override
	public String checkStatues(CarApply carApply) {
		// TODO Auto-generated method stub
		CarManage carManage = carDao.selectStatusById(carApply);
		if(carManage==null){
			return "0";
		}
		Integer result = carDao.selectStatus(carApply);
		System.out.println(result);
		if(result==null){
			return "1";
		}
		return "2";
	}

	@Override
	public String changeApplyStatue(Map<String, Object> map) {
		// TODO Auto-generated method stub
		
		
		Integer result = carDao.updateCarApplySt(map);		
		if(result!=0){
			return "true";
		}
		return "false";
	}

	@Override
	public String changeCarManage(CarManage carManage) {
		// TODO Auto-generated method stub
		Integer result = carDao.updateCarManageInfo(carManage);
		if(result!=0){
			return "true";
		}
		return "false";
	}

}
